package socket.client;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Serializable;
import java.net.Socket;

class Handler extends Thread implements Serializable{
    	 protected Socket client;
    	 protected Message str;
    	 public Handler(Socket socket) {
    	  this.client = socket;
    	 }
    	 public void run() {
    	  try {
    		  ObjectInputStream in = new ObjectInputStream(client.getInputStream());
    		  Object a = in.readObject();
    		  str = (Message) a;
              System.out.println("S: Received: '" + str.getStr() + "'");
              //System.out.println("����;");
              PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(client.getOutputStream())),true);
              out.println("Server Received " + str.getStr());
             
              
    	  } catch(IOException e) {
    	  } catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
    	  finally {
    	   try {
    		 client.close();
    	   } 
    	   catch(IOException ignored) {}
    	  }
    	 }
    }